package com.zlzxm.shoesmarket.view.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.activity.manage.ActivityIndex;
import com.zlzxm.shoesmarket.view.adapter.ADGoodsSize;
import com.zlzxm.shoesmarket.view.adapter.ADRepository;
import com.zlzxm.shoesmarket.view.widget.simpleead.OnItemclicklistener;
import com.zlzxm.shoesmarket.view.widget.simpleead.SimpleHead;
import com.zlzxm.shoesmarket.viewmodel.VMRepositoryManager;

/**
 * Created by zlz
 * on  4/14/21
 * <br> 仓库管理
 */
public class ACRepositoryManager extends BaseActivity implements OnItemClickListener {

    public static void start(Context context) {

        Intent starter = new Intent(context, ACRepositoryManager.class);

        context.startActivity(starter);
    }

    private VMRepositoryManager vmRepositoryManager;

    private ADRepository  adRepository = new ADRepository();

    private RecyclerView recyclerView;


    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.ac_repository_manager);
        SimpleHead simpleHead = ZViewHelp.findById(this,R.id.head);
        simpleHead.setTitle("仓库管理");

        simpleHead.setOnItemclicklistener(new OnItemclicklistener() {
            @Override
            public void onRightItemClick() {

                ActivityIndex.startACAddRepository(ACRepositoryManager.this);
            }

            @Override
            public void onTitleClick() {

            }

            @Override
            public void onRightTxtClick() {

            }

            @Override
            public void onLeftItemClick() {

                finish();
            }
        });

        recyclerView = ZViewHelp.findById(this,R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        adRepository.setOnItemClickListener(this);
    }

    @Override
    protected void initViewModule() {
        super.initViewModule();
        vmRepositoryManager = new ViewModelProvider(this).get(VMRepositoryManager.class);

        vmRepositoryManager.getLiveRepository().observe(this,adRepository::setList);
    }

    @Override
    protected void initData() {
        super.initData();
        recyclerView.setAdapter(adRepository);
        vmRepositoryManager.requestRepository();
    }

    @Override
    public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

        ActivityIndex.startACUpdateRepository(this,adRepository.getData().get(position).getId());

    }
}
